package com.java.JVMTest;

/**
 * 堆和栈
 */
public class HeapAndStack {

    public static void main(String[] args) {
        Person yPerson = new Person("5");

        Person oPerson = new Person("100");

        swapAge(yPerson, oPerson);//能成功交换年龄吗？

        System.out.println("yPerson.age=" + yPerson.getAge());

        System.out.println("oPerson.age=" + oPerson.getAge());

        changeAge(oPerson);//更改后的年龄是多少了？

        System.out.println("oPerson.age=" + oPerson.getAge());

    }

    private static void swapAge(Person p1, Person p2) {
        Person temp = p1;

        p1 = p2;

        p2 = temp;

    }

    private static void changeAge(Person person) {
        person.setAge("5");

        person = new Person("30");

        person.setAge("40");

    }

    static class Person {
        private String age;

        public Person(String age) {
            this.age = age;

        }

        public String getAge() {
            return age;

        }

        public void setAge(String age) {
            this.age = age;
        }
    }
}
